import 'dart:convert';

import 'package:surfaceim/common/apis/apis.dart';
import 'package:surfaceim/common/entities/entities.dart';
import 'package:surfaceim/common/services/services.dart';
import 'package:surfaceim/common/values/values.dart';
import 'package:get/get.dart';

/// 字典数据

class Dictionaries extends GetxController {
  static Dictionaries get to => Get.find();

  /// 用户设置字典
  var _userConfig = UserConfig();

  /// 用户信息配置
  UserConfig get userConfig => _userConfig;

  @override
  void onInit() {
    super.onInit();
  }

  // 获取用户配置字典
  Future<void> conf() async {
    UserConfig result = await DictionariesAPI.conf();
    if (result.code.toString() == '1') {
      _userConfig = result;
    }
  }

  // 获取系统地域信息
  Future<void> area() async {
    var result = await DictionariesAPI.area();
    if (result.code.toString() == '1') {
      StorageService.to
          .setString(STORAGE_SYSTEM_AREA, jsonEncode(result.listArea));
    }
  }
}
